﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// CommonUse 的摘要说明
/// </summary>
public class SysManage
{
  public SysManage()
  {
    //
    // TODO: 在此处添加构造函数逻辑
    //
  }

  /// <summary>
  /// 获取登陆用户User,如果未登陆为""
  /// </summary>
  public static string Get_User
  {
    get
    {
      return HttpContext.Current.User.Identity.IsAuthenticated ? HttpContext.Current.User.Identity.Name : "";
    }

  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="sUser"></param>
  public static void Signin(string sUser)
  {
    System.Web.Security.FormsAuthenticationTicket tk = new System.Web.Security.FormsAuthenticationTicket(1, sUser, DateTime.Now, DateTime.Now.AddYears(1), true, "", System.Web.Security.FormsAuthentication.FormsCookiePath);
    string key = System.Web.Security.FormsAuthentication.Encrypt(tk);//得到加密后的身份验证票字串


    HttpCookie ck = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, key);
    ck.Domain = System.Web.Security.FormsAuthentication.CookieDomain;  // 这句话在部署网站后有用，此为关系到同一个域名下面的多个站点是否能共享Cookie
    HttpContext.Current.Response.Cookies.Add(ck);
    //HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddYears(1);
    //System.Web.Security.FormsAuthentication.SetAuthCookie(sUser, true);

  }

  /// <summary>
  /// 退出系统
  /// </summary>
  public static void Signout()
  {
    System.Web.Security.FormsAuthentication.SignOut();
  }
}
